

******BONUS IMPLEMENTATION QUALITY (TABLE C.6)********


set more off
clear all 
clear matrix
capture log close

adopath + "$main/DoFiles"																		


local seed = 999
local reps = 5000



//--> DATA: FA SURVEY OUTCOMES
	*********************************************************************************************************************************************************

		use "$data/fASVY.dta", clear
		
		local know_var fcorrect_threshold fthresholds_realistic ffa_equal_chance //--> FOR 78 TREATMENT FAS
		
		
//--> DATA: FA TREATMENT STATUS 
	*********************************************************************************************************************************************************
	
		sort fw_code
		merge fw_code using "$data/FWHR.dta"
		drop _m					
					
		
		//--> REGION DUMMIES
				tab region, gen(r)
				
		//--> SELECTION INTO FOLLOWUP SURVEY 
		
				g endline= 1 if fname_thing_likemost_nrsp!=.
				

//--> OUTPUT: TABLE C.6 PANEL A (BONUS KNOWLEDGE OUTCOMES: 3 DUMMIES)	
	*********************************************************************************************************************************************************
			
			keep if treat==1 & endline==1
			
			g bonus_status = 0 if treat==1
			replace bonus_status = 1 if treat_credit==1
			replace bonus_status = 2 if treat_sm==1
			
			
			//--> COLUMNS 1-3: MEANS BY TREATMENT STATUS
			*****************************************
		
				putexcel set "$output/tableC_6A (col1-3)", replace
					putexcel A1 = "var name"
					putexcel B1 = "credit & social bonus"
					putexcel C1 = "credit bonus"
					putexcel D1 = "social bonus"
				
				local count = 2
				foreach v in `know_var' {
					putexcel A`count' = "`v'"
					mean `v'
					putexcel B`count' = matrix(e(b))
					mean `v', over (bonus_status)
					putexcel C`count' = matrix(e(b))
					local count = `count' + 1
					}
					
					putexcel A`count' = "No. of FAs"
					putexcel B`count' = matrix(e(N))
					putexcel C`count' = matrix(e(_N))
	

		//--> COLUMNS 4-6: T-BOOT & RANDOMIZATION INFERENCE BASED P VALUES
			****************************************		
				
				log using "$output/tableC_6A (col4-5)", replace	
				
				
					foreach v in `know_var' {
						cgmwildboot `v' r1 r2 r3 treat_sm if endline==1 & treat==1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed')
						}
						
					foreach v in `know_var' {
						randcmd((treat_sm) reg `v' treat_sm r1 r2 r3 if endline==1 & treat==1, cluster(fu_feb05)), treatvars(treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') 
						}
				log close
					
	*********************************************************************************************************************************************************
	
	
//--> DATA: BONUS PAYMENT FWHR
	*********************************************************************************************************************************************************
		
		use "$data/bonus_FAmth_level_vars.dta", clear
		
		//--> IDENTIFY TREATMENT STATUS
				
				sort fw_code
				merge fw_code using "$data/FWHR.dta", nok
				drop _m
	
		//--> DROP CONTROL FAS
		
				keep if treat==1
				
		//--> KEEP BONUS PAYMENT TRANSACTIONS
		
				keep if thres_AB==1
		
		
		//--> PAID FULL AMOUNT
		
				g full_amount = (bonus_amount == amountpay)
				
		//--> PAID ON TIME		
				g on_time = 0
				replace on_time = 1 if ((monpay=="April-05"|monpay=="May-05"|monpay=="June-05") & month==11)
				replace on_time = 1 if (monpay=="May-05"|monpay=="June-05"|monpay=="July-05") & month==12
				replace on_time = 1 if (monpay=="June-05"|monpay=="July-05"|monpay=="August-05") & month==13
				replace on_time = 1 if (monpay=="July-05"|monpay=="August-05"|monpay=="September-05") & month==14
				replace on_time = 1 if (monpay=="August-05"|monpay=="September-05"|monpay=="October-05") & month==15
				replace on_time = 1 if (monpay=="September-05"|monpay=="October-05"|monpay=="November-05") & month==16
				replace on_time = 1 if (monpay=="October-05"|monpay=="November-05"|monpay=="December-05") & month==17
				replace on_time = 1 if (monpay=="November-05"|monpay=="December-05"|monpay=="January-06"|monpay=="January-05") & month==18
				replace on_time = 1 if (monpay=="December-05"|monpay=="January-06"|monpay=="January-05"|monpay=="February-06") & month==19
				replace on_time = 1 if (monpay=="February-06"|monpay=="January-06"|monpay=="January-05"|monpay=="March-06") & month==20
				replace on_time = 1 if (monpay=="February-06"|monpay=="March-06") & month==21
				replace on_time = 1 if (monpay=="March-06"|monpay=="April-06"|monpay=="May-06") & month==22
				replace on_time = 1 if (monpay=="April-06"|monpay=="May-06"|monpay=="June-06") & month==23
				replace on_time = 1 if (monpay=="May-06"|monpay=="June-06"|monpay=="July-06") & month==24
				replace on_time = 1 if (monpay=="June-06"|monpay=="July-06"|monpay=="August-06") & month==25

				replace monpay = "January-06" if monpay=="January-05"
				
		//--> DELAY ON PAYMENT (MONTHS PAST 2 MNTHS)	
		
				g monpay_month = . 
				
				local var April-05 May-05 June-05 July-05 August-05 September-05 October-05 November-05 December-05 January-06 February-06 March-06 April-06 May-06 June-06 July-06 August-06 
				local m = 11
				foreach v in `var' {
					replace monpay_month = `m' if monpay =="`v'"
					local m = `m' + 1
					}
				
				g delay_month = monpay_month - month
				replace delay_month = 0 if on_time==1
				replace delay_month = delay_month - 2 if on_time==0
				
				

//--> OUTPUT: TABLE C.6 PANEL B (BONUS TRASACTIONS)	
	*********************************************************************************************************************************************************
						
			g bonus_status = 0 if treat==1
			replace bonus_status = 1 if treat_credit==1
			replace bonus_status = 2 if treat_sm==1
			
			local bonus_var full_amount on_time delay_month 
			
			//--> COLUMNS 1-3: MEANS BY TREATMENT STATUS
			*****************************************
		
				putexcel set "$output/tableC_6B (col1-3)", replace
					putexcel A1 = "var name"
					putexcel B1 = "credit & social bonus"
					putexcel C1 = "credit bonus"
					putexcel D1 = "social bonus"
				
				local count = 2
				foreach v in `bonus_var' {
						putexcel A`count' = "`v'"
					mean `v'
						putexcel B`count' = matrix(e(b))
					mean `v', over (bonus_status)
						putexcel C`count' = matrix(e(b))
					local count = `count' + 1
					}
					
					putexcel A`count' = "No. of Trasactions"
					putexcel B`count' = matrix(e(N))
					putexcel C`count' = matrix(e(_N))
		

		//--> COLUMNS 4-6: T-BOOT & RANDOMIZATION INFERENCE BASED P VALUES
			****************************************		
				tab region, gen(r)
				
				log using "$output/tableC_6B (col4-5)", replace	
				
				
					foreach v in `bonus_var' {
						cgmwildboot `v' r1 r2 r3 treat_sm if treat==1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed')
						}
						
					foreach v in `bonus_var' {
						randcmd((treat_sm) reg `v' treat_sm r1 r2 r3 if treat==1, cluster(fu_feb05)), treatvars(treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') 
						}
				
				log close
					
	*********************************************************************************************************************************************************
	
			
				
